<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">会员卡</block>
		</cu-custom>
		<view class="container">
			<view class="bg-white">
				<view class="padding text-lg solid-bottom">未办下列会员卡的情况下扫码进离店——计时收费（0.4元/分钟）</view>
				<radio-group class="block" @change="cardTypeChange">
					<view v-for="(cartType, index) in cardTypes" :key="index"
						class="flex justify-between align-center padding solid-bottom">
						<view class="title">{{cartType.name}}</view>
						<radio :value="''+cartType.cardTypeId"></radio>
					</view>
				</radio-group>
				<view class="padding flex flex-direction">
					<button @tap="payCard" class="cu-btn bg-blue lg">确定</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad: function() {
			this.state = this.common.getState();
			this.init();
		},
		data: function() {
			return {
				state: {},
				cardTypeId: 0,
				cardType: {},
				cardTypes: []
			};
		},
		methods: {
			cardTypeChange: function(e) {
				this.cardTypeId = e.detail.value;

				for (let index in this.cardTypes) {
					let item = this.cardTypes[index];
					if (item.cardTypeId == this.cardTypeId) {
						this.cardType = item;
						break;
					}
				}

				console.log(this.cardType);
			},
			init: function() {
				let self = this;
				this.http.get({
					url: "/client/card-type/all"
				}).then(function(res) {
					self.cardTypes = res;
				});
			},
			payCard: function() {
				console.log(11111)
				let self = this;
				this.http.get({
					url: "/client/account",
					param: {
						clientId: self.state.autor.store_client.clientId,
					}
				}).then(function(data) {
					
						console.log(data)
					// let self = this;
					if (self.cardTypeId == 0) {
						self.message.warning("请选择您要办理的会员卡类型");
						return;
					}
					uni.showModal({
						title: '发起支付',
						content: '支付办理' + self.cardType.name + '费用' + self.cardType.amount / 100 + '元',
						success: function(res) {
							if (res.confirm) {
								self.http.post({
									url: "/client/card-record/info",
									param: {
										storeId: self.state.autor.store_client.storeId,
										clientId: self.state.autor.store_client.clientId,
										openId: self.state.autor.store_client.openId,
										cardTypeId: self.cardTypeId,
										amount: self.cardType.amount,
									}
								}).then(function(data) {
									console.log(data);

									self.pay.exePay(data).then(resPay => {
										uni.navigateTo({
											url: "../pages/vip"
										});
									});

									// self.jweixin.config({
									//   debug: false,
									//   appId: data.appId,
									//   timestamp: data.timeStamp,
									//   nonceStr: data.nonceStr, 
									//   signature: data.paySign,
									//   jsApiList: ["chooseWXPay"]
									// });

									// self.jweixin.ready(function() {
									// 	self.jweixin.chooseWXPay({
									// 	  timestamp: data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
									// 	  nonceStr: data.nonceStr, // 支付签名随机串，不长于 32 位
									// 	  package: data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
									// 	  signType: data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
									// 	  paySign: data.paySign, // 支付签名
									// 	  success: function (res) {
									// 	    // 支付成功后的回调函数
									// 		self.message.info("支付成功");
									// 		uni.navigateTo({
									// 			url: "../pages/vip"
									// 		});
									// 	  }
									// 	});
									// });
								});
							} else if (res.cancel) {}

						}
					});
				}).catch(function(code) {
					console.log(code)
					if ("PAY_DEPOSIT" === code) {
						uni.navigateTo({
							url: "../pages/deposits"
						});
					}
				});




			}
		}
	}
</script>

<style>
</style>